<?php

/**
 * @author 
 * @copyright 2009
 */
$secured = array("mod_leftblock", "mod_rightblock", "mod_topblock", "mod_bottomblock", "mod_menutop", "mod_menuleft", "mod_menuright");
$modules = dirlist('../modules/');

if(!empty($_GET['file'])){
	if(!in_array(strtolower($_GET['file']), $secured)){
	$_GET['file'] = str_replace("/", " ", $_GET['file']);
	$_GET['file'] = str_replace("../", " ", $_GET['file']);
	$_GET['file'] = str_replace("..", " ", $_GET['file']);
	rmdirr('../modules/'.$_GET['file']);
	
	$log->write(8, 'com_install', 'NOW()', 'User has deleted module '.$_GET['file'], $_SESSION['id']);
	echo '<p class="msg done">'.Lang::getBackGlobal('install_delete_done').'</p>';
	echo '<meta http-equiv="refresh" content="4;url=index.php?p=install&type=del_mod">';
	}else{
		echo '<p class="msg error">'.Lang::getBackGlobal('install_delete_module_protected').'</p>';
	}
}

$i = 1;
echo '<table>';
echo "<tr><th>#</th><th>".Lang::getBackGlobal('install_module')."</th><th>".Lang::getBackGlobal('install_version')."</th><th>".Lang::getBackGlobal('install_author')."</th><th>".Lang::getBackGlobal('action')."</th></tr>";
foreach($modules as $key){
	
	if(is_file('..'.DIR_SEP.'modules'.DIR_SEP.$key.DIR_SEP.'info.xml')){

    $xml = simplexml_load_file('..'.DIR_SEP.'modules'.DIR_SEP.$key.DIR_SEP.'info.xml');
    $author = (string)$xml->info[0]->author;
    $version = (string)$xml->info[0]->version;

	}else{
		$author = 'unknown';
		$version = 'unknown';
	}
	
	if(!in_array(strtolower($key), $secured)){
		$action = '<a href="#" onclick="javascript:confirm_uninstall(\''.$key.'\', \'index.php?p=install&type=del_mod&file='.$key.'\');return false;">'.Lang::getBackGlobal('install_delete').'</a>';
	}else{
		$action = '<em>'.Lang::getBackGlobal('install_delete_protected').'</em>';
	}
	
	echo '<tr><td>'.$i.'</td><td>'.$key.'</td><td>'.$version.'</td><td>'.$author.'</td><td>'.$action .'</td></tr>';
	$i++;
}
echo "\n</table>";
?>